import { defineStore } from 'pinia';
import { ProcessDeploymentInfoVO } from '@/entiy/vo/ProcessDeploymentInfoVO.ts';
import RequestService from '@/service/RequestService.ts';
import { PageVO } from '@/entiy/vo/PageVO.ts';
import PromiseUtils from '@/utils/PromiseUtils.ts';

interface FormData {
    pageNum: number,
    pageSize: number,
    startDateTime: string;
    endDateTime: string;
    deploymentName: string;
}

export const useProcessDeploymentComponentStore = defineStore('processDeploymentComponentStore', {
    state: () => {
        return {
            // 搜索表单
            formData: {} as FormData,

            // 表格数据
            tableLoading: false,
            tableDataList: [] as Array<ProcessDeploymentInfoVO>,

            // 分页信息
            pageNum: 1,
            pageSize: 10,
            totalRow: 0,
        };
    },

    getters: {},

    actions: {
        async queryTableDataList(): Promise<void> {
            this.formData.pageNum = this.pageNum;
            this.formData.pageSize = this.pageSize;

            const result = await RequestService.post<PageVO<ProcessDeploymentInfoVO>>("/test/query-deployment-info-list", this.formData);
            if (result.isError) {
                return PromiseUtils.reject(result.errorMsg);
            }

            this.totalRow = result.bizDta.totalRow;
            this.tableDataList = result.bizDta.recordList;
        }
    }
});
